<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script>
        //请求某个图片资源
        function requestImg() {
            var p = new Promise(function (resolve, reject) {
                var img = new Image();
                img.onload = function () {
                    resolve(img);
                }
                img.src = 'xxxxxx';
            });
            return p;
        }

        //延时函数，用于给请求计时
        function timeout() {
            var p = new Promise(function (resolve, reject) {
                setTimeout(function () {
                    reject('图片请求超时');
                }, 5000);
            });
            return p;
        }

        Promise.race([requestImg(), timeout()])
            .then(function (data) {
                console.log('==data=' + data);
            })
            .catch(function (error) {
                console.log('error==' + error);
            });
    </script>
</head>

<body>


<div class="warp">

</div>
</body>
</html>